{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f4d4724b",
   "metadata": {},
   "source": [
    "------\n",
    "* 2022-10-18 week 09\n",
    "* python课堂笔记\n",
    "* 记录人:梁颖\n",
    "------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ace7125f",
   "metadata": {},
   "source": [
    "# 本周知识点"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5992681b",
   "metadata": {},
   "source": [
    "> 1. while循环\n",
    "> 2. 购物车练习\n",
    "> 3. 元组_集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b61d38c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙,缠缠绵绵到天涯... 0\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 1\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 2\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 3\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 4\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 5\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 6\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 7\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 8\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 9\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 10\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 11\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 12\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 13\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 14\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 15\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 16\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 17\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 18\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 19\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 20\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 21\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 22\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 23\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 24\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 25\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 26\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 27\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 28\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 29\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 30\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 31\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 32\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 33\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 34\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 35\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 36\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 37\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 38\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 39\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 40\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 41\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 42\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 43\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 44\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 45\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 46\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 47\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 48\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 49\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 50\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 51\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 52\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 53\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 54\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 55\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 56\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 57\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 58\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 59\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 60\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 61\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 62\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 63\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 64\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 65\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 66\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 67\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 68\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 69\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 70\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 71\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 72\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 73\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 74\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 75\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 76\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 77\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 78\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 79\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 80\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 81\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 82\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 83\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 84\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 85\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 86\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 87\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 88\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 89\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 90\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 91\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 92\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 93\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 94\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 95\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 96\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 97\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 98\n",
      "你是风儿我是沙,缠缠绵绵到天涯... 99\n"
     ]
    }
   ],
   "source": [
    "# while True 可以实现 for + range 的方法\n",
    "# while True 一般用于不确定的循环次数或者无限次循环操作\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"你是风儿我是沙,缠缠绵绵到天涯...\",count)\n",
    "    count += 1\n",
    "    if count == 100:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "bd4ddac6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card:66\n"
     ]
    }
   ],
   "source": [
    "# 猜数字小游戏：0<n<100,5次机会猜数字，每次猜完出题人提示‘你猜的有点大/有点小’\n",
    "\n",
    "hide_card = int(input(\"hide_card:\")) # 出题人\n",
    "count = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5b69de5c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card:········\n",
      "游戏开始了\n",
      "guess_digit:60\n",
      "往大了猜.\n",
      "guess_digit:88\n",
      "往小了想想.\n",
      "guess_digit:70\n",
      "yes,you got it!\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[0;32mIn [13]\u001b[0m, in \u001b[0;36m<cell line: 5>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      7\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[1;32m      8\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m count \u001b[38;5;241m<\u001b[39m \u001b[38;5;241m5\u001b[39m :\n\u001b[0;32m----> 9\u001b[0m         guess_digit \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mguess_digit:\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m) \u001b[38;5;66;03m# 玩游戏的人\u001b[39;00m\n\u001b[1;32m     10\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m guess_digit \u001b[38;5;241m==\u001b[39m hide_card:\n\u001b[1;32m     11\u001b[0m             \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myes,you got it!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "File \u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[0;34m(self, prompt)\u001b[0m\n\u001b[1;32m   1071\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_allow_stdin:\n\u001b[1;32m   1072\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[1;32m   1073\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m   1074\u001b[0m     )\n\u001b[0;32m-> 1075\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m   1076\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   1077\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   1078\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   1079\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m   1080\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[0;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[1;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[1;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[1;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[0;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[1;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[1;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "import getpass\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "count = 0\n",
    "# print(high_card)\n",
    "if hide_card < 100 and hide_card > 0 :\n",
    "    print(\"游戏开始了\")\n",
    "    while True:\n",
    "        if count < 5 :\n",
    "            guess_digit = int(input(\"guess_digit:\")) # 玩游戏的人\n",
    "            if guess_digit == hide_card:\n",
    "                print(\"yes,you got it!\")\n",
    "            elif guess_digit > hide_card:\n",
    "                print(\"往小了想想.\")\n",
    "            else:\n",
    "                print(\"往大了猜.\")\n",
    "            count = count + 1\n",
    "        else:\n",
    "            print(\"猜这么多次都不对,你个笨蛋!\")\n",
    "            print(\"正确答案：%s\"%(hide_card))\n",
    "            break\n",
    "else:\n",
    "     print(\"请输入数字在0-99之间。不要耍赖！\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "36120261",
   "metadata": {},
   "source": [
    "## 购物车"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5eb91a8c",
   "metadata": {},
   "source": [
    "* 购物车程序项目：\n",
    "\n",
    "> 1.运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。  \n",
    "> 2.让用户输入商品编号进行商品的购买。  \n",
    "> 3.用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。  \n",
    "> 4.用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d26a1190",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额：4\n",
      "------蜜雪冰城商品列表------\n",
      "0 蜜桃乌龙 6元\n",
      "1 柠檬四季春 4元\n",
      "2 草莓啵啵奶盖 13元\n",
      "3 杨枝甘露 12元\n",
      "请输入商品编号：1\n",
      "购买成功，请等待制作...您的余额还有：0元\n",
      "------蜜雪冰城商品列表------\n",
      "0 蜜桃乌龙 6元\n",
      "1 柠檬四季春 4元\n",
      "2 草莓啵啵奶盖 13元\n",
      "3 杨枝甘露 12元\n"
     ]
    }
   ],
   "source": [
    "# 1 运行程序后，让用户输入支付宝余额✔️，然后打印我们的商品列表给用户✔️。\n",
    "good_list = [\n",
    "    [\"蜜桃乌龙\",6],\n",
    "    [\"柠檬四季春\",4],\n",
    "    [\"草莓啵啵奶盖\",13],\n",
    "    [\"杨枝甘露\",12],\n",
    "]\n",
    "# 数据存放，列表的增加（append）\n",
    "shopping_list = []\n",
    "AliPay = int(input(\"请输入余额：\"))\n",
    "\n",
    "while True:\n",
    "    print(\"------蜜雪冰城商品列表------\")  \n",
    "    for i in range(4):    # print(good_list[1/2/3][0],good_list[1/2/3][1])    \n",
    "        print(i,good_list[i][0],str(good_list[i][1])+\"元\") \n",
    "    # 2 让用户输入商品编号✔️,进行商品的购买✔️。 \n",
    "    user_choise = input(\"请输入商品编号：\")\n",
    "    # 3 用户选择商品后，检查用户的余额是否够✔️，若够则直接扣款✔️，不够则提醒用户✔️。         \n",
    "    # 3.1 用户输入商品序号（数值）\n",
    "    if user_choise.isdigit() and int(user_choise) < len(good_list) and int(user_choise)>= 0:\n",
    "        user_choise = int(user_choise)\n",
    "        if AliPay >= good_list[user_choise][1]:\n",
    "            # 余额足够\n",
    "            AliPay = AliPay - good_list[user_choise][1] # 更新用户余额\n",
    "            shopping_list.append(good_list[user_choise])\n",
    "            print(\"购买成功，请等待制作...您的余额还有：%s元\"%(AliPay))      \n",
    "        else:\n",
    "            # 余额不够\n",
    "            print(\"您的余额不足\"+str(good_list[user_choise][1] )+\"元，请更换支付方式或选择其他商品～欢迎再来尝试～\")\n",
    "    # 3.2 用户输入其他\n",
    "    elif user_choise ==\"q\":\n",
    "        print(\"感谢您的购买，欢迎下次光临～\")\n",
    "        print(\"您的购物车：\",shopping_list)\n",
    "        print(\"您的余额还有：\",AliPay)\n",
    "        break\n",
    "    else:\n",
    "        print(\"您输入的商品不存在或您输入的内容有误！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "523532df",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
